<template>
  <div class="home">
    <h1>欢迎使用Simple Deploy</h1>
    <el-row :gutter="20">
      <el-col :span="8" v-for="(item, index) in applications" :key="index">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>{{ item.name }}</span>
              <el-button class="button" type="primary" @click="handleInstall(item)">
                安装
              </el-button>
            </div>
          </template>
          <div class="text item">
            {{ item.description }}
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '../stores/user'
import { ElMessage } from 'element-plus'

const router = useRouter()
const authStore = useAuthStore()

const applications = ref([
  { name: 'Nginx', description: '高性能的HTTP和反向代理web服务器' },
  { name: 'MySQL', description: '最流行的开源关系数据库管理系统' },
  { name: 'Redis', description: '开源的高性能key-value数据库' },
  { name: 'Node.js', description: '基于Chrome V8引擎的JavaScript运行环境' },
  { name: 'Python', description: '简单易学的高级编程语言' },
  { name: 'Docker', description: '开源的应用容器引擎' }
])

const handleInstall = (app) => {
  if (!authStore.isAuthenticated) {
    ElMessage.warning('请先登录')
    router.push('/login')
    return
  }

  // 这里添加安装逻辑
  ElMessage.success(`开始安装 ${app.name}`)
}
</script>

<style scoped>
.home {
  padding: 20px;
}

.box-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}
</style>
